Skip to content

Rewrite Initium from Go to Rust#13

Merged
mikkeldamsgaard merged 4 commits into
mainfrom
rust-rewrite
Feb 23, 2026
Merged

Rewrite Initium from Go to Rust#13
mikkeldamsgaard merged 4 commits into
mainfrom
rust-rewrite

Conversation

@mikkeldamsgaard

Copy link
Copy Markdown
Contributor

Summary

Complete rewrite of Initium from Go to Rust, reducing Docker image size by 76%.

What changed

Language & Toolchain

  • Go 1.25 → Rust 1.85 (musl static linking)
  • cobra → clap for CLI
  • Go text/template → minijinja (Jinja2-style) for template rendering
    Binary / Image Size
    | | Go | Rust | Reduction |
    |---|---|---|---|
    | Docker image (scratch) | ~7.4 MB | 1.83 MB | 76% |
    All 6 subcommands reimplemented:
  • wait-for — TCP + HTTP/HTTPS with retries, backoff, jitter
  • migrate — command exec with lock-file idempotency
  • seed — command exec with structured logging
  • render — envsubst + Jinja2 templates (via minijinja)
  • fetch — HTTP fetch with auth, TLS, retry
  • exec — arbitrary command with workdir
    CI/CD updated:
  • CI: cargo test + clippy + rustfmt
  • Release: Rust toolchain, same Docker buildx multi-arch flow
  • Both Dockerfiles (scratch + jyq) rewritten for Rust
    Docs updated:
  • design.md: Rust architecture, directory structure, how-to-add-subcommand
  • usage.md: template mode → Jinja2
  • README.md, FAQ.md: image sizes, tool references
  • CHANGELOG.md: Rust rewrite entry
  • tests/README.md: cargo test references

Test results

test result: ok. 36 passed; 0 failed; 0 ignored

How to verify

cargo test          # 36 tests pass
cargo build --release
./target/release/initium --help
docker build -t test -f Dockerfile .
docker run --rm test --version

Breaking changes

  • Template mode gotemplate now uses Jinja2 syntax: {{ env.VAR }} instead of {{.VAR}}
  • Build requires Rust toolchain instead of Go

Complete reimplementation of all 6 subcommands in Rust:
- wait-for (TCP + HTTP/HTTPS with retries, backoff, jitter)
- migrate (command exec with lock file idempotency)
- seed (command exec with structured logging)
- render (envsubst + Jinja2 templates via minijinja)
- fetch (HTTP fetch with auth, TLS, retry)
- exec (arbitrary command with workdir support)
Key dependencies: clap, ureq+rustls, serde_json, minijinja, regex, chrono
36 unit tests covering: logging, retry, safety, render modules
All tests passing.
Binary size comparison (release, stripped, musl-linked):
- Go binary (scratch): ~7.4 MB
- Rust binary (scratch): ~1.8 MB (76% reduction)
Docker image (scratch + binary + CA certs): 1.83 MB total
- CI workflow: replace setup-go with dtolnay/rust-toolchain, use
  cargo test/clippy/fmt instead of go test/vet/staticcheck
- Release workflow: use dtolnay/rust-toolchain for pre-push tests
- jyq.Dockerfile: rewrite for Rust (rust:1.85-alpine builder, cargo build)
- Dockerfile: already updated in prior commit
- docs/design.md: update architecture diagram, directory structure,
  and 'How to Add a Subcommand' guide for Rust/clap
- docs/usage.md: update template mode description (Go text/template -> minijinja)
- README.md, FAQ.md: update image sizes (10MB -> 2MB), tool references
- CHANGELOG.md: add Rust rewrite entry, update references
- CLAUDE.md: add project config with cargo test references
- tests/README.md: update from go test to cargo test
- Fix dead_code warnings: allow unused Warn variant and warn() method
- Fix useless .into() conversion in logging JSON output
- Fix manual Range::contains in fetch status check
- Fix unit let-binding in command execution
- Fix lines().flatten() -> lines().map_while(Result::ok)
- Apply cargo fmt to all source files
@mikkeldamsgaard mikkeldamsgaard merged commit 66728a3 into main Feb 23, 2026
4 checks passed
@mikkeldamsgaard mikkeldamsgaard deleted the rust-rewrite branch February 26, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant